package com.seafwg.controller;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.beans.PropertyVetoException;

/**
 * @Author seafwg
 * @Date 2022/3/4 9:21 上午
 * @Version 1.0
 * @description xxx
 */
@Controller
@CrossOrigin
@ResponseBody
@RequestMapping("/jdbc")
public class JdbcTemplateController {

    @RequestMapping("/test")
    public void jdbcTemplateTest() throws PropertyVetoException {
        System.out.println("123");
        // 1.创建数据源对象
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/changgou_goods");
        dataSource.setUser("root");
        dataSource.setPassword("seafwg123");
        // 2.创建jdbcTemplate对象
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSource);
        int update = jdbcTemplate.update("insert into account values(?, ?)", "Tom", 5000);
        System.out.println(update);
    }
}
